<?php defined('InNcPHP') or exit('Access Invalid!');?>

<script type="text/javascript" src="<?php echo RESOURCE_URL;?>/common/jquery-ui/jquery.ui.js"></script>
<script type="text/javascript" src="<?php echo RESOURCE_URL;?>/common/jquery-ui/i18n/zh-CN.js" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="<?php echo RESOURCE_URL;?>/common/jquery-ui/themes/ui-lightness/jquery.ui.css"  />

<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <h3><?php echo $lang['order_index'];?></h3>
            <?php echo $output['top_link'];?>
        </div>
    </div>
    <div class="fixed-empty"></div>
    <!--  搜索表单  -->
    <form method="get" name="formSearch" id="formSearch">
        <input type="hidden" value="customize" name="act">
        <input type="hidden" value="index" name="op">
        <table class="tb-type1 noborder search">
            <tbody>
            <tr>
                <th><label> <?php echo $lang['customize_company'].'/'.$lang['customize_username'];?></label></th>
                <td><input type="text" name="search_com" value="<?php echo $output['search']['search_com']; ?>" class="txt"></td>
                <th><label><?php echo $lang['customize_addtime'];?></label></th>
                <td><input type="text" name="search_stime" value="<?php echo $output['search']['search_stime']; ?>" id="search_stime" class="txt date"></td>
                <td><input type="text" name="search_etime" value="<?php echo $output['search']['search_etime']; ?>" id="search_etime" class="txt date"></td>
            </tr>
            <tr>
                <th><label> <?php echo $lang['customize_type'];?></label></th>
                <td>
                    <select name="search_type">
                        <option value=""><?php echo $lang['nc_please_choose'];?>...</option>
                        <?php if (is_array($output['types'])): ?>
                            <?php foreach ($output['types'] as $k => $v): ?>
                                <option value="<?php echo $k; ?>" <?php echo is_numeric($output['search']['search_type']) && $output['search']['search_type'] == $k ? 'selected' : ''; ?>><?php echo $v; ?></option>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </select>
                </td>
                <th><label> <?php echo $lang['customize_status'];?></label></th>
                <td>
                    <select name="search_status">
                        <option value=""><?php echo $lang['nc_please_choose'];?>...</option>
                        <?php if (is_array($output['status'])): ?>
                            <?php foreach ($output['status'] as $k => $v): ?>
                                <option value="<?php echo $k; ?>" <?php echo is_numeric($output['search']['search_status']) && $output['search']['search_status'] == $k ? 'selected' : ''; ?>><?php echo $v; ?></option>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </select>
                </td>
                <td>
                    <a href="javascript:void(0);" onclick="$('#formSearch').submit();" class="btn-search"></a>
                    <?php if ($output['search']['search_com'] || $output['search']['search_stime'] || $output['search']['search_etime'] || is_numeric($output['search']['search_type']) || is_numeric($output['search']['search_status'])): ?>
                    <a href="index.php?act=customize&op=index" class="btns "><span><?php echo $lang['nc_cancel_search']?></span></a>
                    <?php endif; ?>
                </td>
            </tr>
            </tbody>
        </table>
    </form>

    <!--  显示列表  -->
    <table class="table tb-type2 nobdb">
        <thead>
        <tr class="thead">
            <th><?php echo $lang['customize_username']?></th>
            <th><?php echo $lang['customize_type']?></th>
            <th><?php echo $lang['customize_company']?></th>
            <th><?php echo $lang['customize_phone']?></th>
            <th><?php echo $lang['customize_num']?></th>
            <th><?php echo $lang['customize_s_addr']; ?></th>
            <th><?php echo $lang['customize_e_addr'];?></th>
            <th><?php echo $lang['customize_require']?></th>
            <th><?php echo $lang['customize_addtime']?></th>
            <th><?php echo $lang['customize_status']?></th>
            <th class="align-center"><?php echo $lang['nc_handle'];?></th>
        </tr>
        <tbody>
        <?php if(!empty($output['lists']) && is_array($output['lists'])){ ?>
            <?php foreach($output['lists'] as $k => $v){ ?>
                <tr class="hover member">
                    <td><?php echo $v['username']; ?></td>
                    <td><?php echo $output['types'][$v['type']]; ?></td>
                    <td><?php echo $v['company']; ?></td>
                    <td><?php echo $v['phone']; ?></td>
                    <td><?php echo $v['num']; ?></td>
                    <td><?php echo $v['s_addr']; ?></td>
                    <td><?php echo $v['e_addr']; ?></td>
                    <td><?php echo $v['require']; ?></td>
                    <td><?php echo date('Y-m-d H:i:s', $v['addtime']); ?></td>
                    <td><?php echo $output['status'][$v['status']]; ?></td>
                    <td class="align-center">
                        <a href="###" onclick="handle(<?php echo $v['id']; ?>);"><?php echo $v['status'] ? '查看' : '处理'; ?></a>
                    </td>
                </tr>
            <?php } ?>
        <?php }else { ?>
            <tr class="no_data">
                <td colspan="11"><?php echo $lang['nc_no_record']?></td>
            </tr>
        <?php } ?>
        </tbody>
        <tfoot class="tfoot">
        <?php if(!empty($output['lists']) && is_array($output['lists'])){ ?>
            <tr>
                <td colspan="16">
                    <div class="pagination"> <?php echo $output['page'];?> </div>
                </td>
            </tr>
        <?php } ?>
        </tfoot>
    </table>
</div>

<!-- 处理表单 -->
<form id="handle" style="display: none;">
    <input type="hidden" name="id" value="">
    <table class="table tb-type2">
        <tbody>
        <!-- 是否联系上客户 -->
        <tr>
            <td colspan="2" class="required">
                <label><?php echo $lang['customize_deal_status'];?>:</label>
                <label><input type="radio" name="deal_status" value="1"> 是</label>
                <label><input type="radio" name="deal_status" value="0"> 否</label>
            </td>
        </tr>
        <!-- 处理人 -->
        <tr>
            <td colspan="2" class="required">
                <label><?php echo $lang['customize_deal_who'];?>: </label>
                <input type="text" name="deal_who">
            </td>
        </tr>
        <!-- 处理备注 -->
        <tr>
            <td colspan="2" class="required"><label><?php echo $lang['customize_deal_remark'];?>:</label></td>
        </tr>
        <tr class="noborder">
            <td class="vatop rowform">
                <textarea name="deal_remark"></textarea>
            </td>
            <td class="vatop tips"></td>
        </tr>
        </tbody>
        <tfoot>
        <tr>
            <td colspan="2"><a href="JavaScript:void(0);" class="btn" id="handle_btn"><span><?php echo $lang['nc_update'];?></span></a></td>
        </tr>
        </tfoot>
    </table>
</form>

<script>
    //开始日期
    $('#search_stime').datepicker({
        dateFormat: 'yy-mm-dd',
        onClose: function(selectedDate) {
            $("#search_etime").datepicker("option", "minDate", selectedDate);
        }
    });
    //结束日期
    $('#search_etime').datepicker({
        dateFormat: 'yy-mm-dd',
        onClose: function(selectedDate) {
            $("#search_stime").datepicker("option", "maxDate", selectedDate);
        }
    });

    //处理函数
    function handle(id) {
        var form = $('#handle');
        $.get('index.php?act=customize&op=get', {id:id}, function (ret) {
            if (ret.datas) {
                form.find('[name="id"]').val(ret.datas.id);
                form.find('[name="deal_who"]').val(ret.datas.deal_who);
                form.find('[name="deal_remark"]').val(ret.datas.deal_remark);
                form.find('[name="deal_status"]').each(function (i) {
                    if (this.value == ret.datas.deal_status) {
                        $(this).attr('checked', true);
                    }
                });
                layer.open({
                    type: 1,
                    title: '<?php echo $lang['nc_new'];?>',
                    area: ['400px', '300px'],
                    content: form,
                    cancel: function () {

                    }
                });
            }
        }, 'json');
    }
    //处理更新
    $('#handle_btn').click(function () {
        $.post('index.php?act=customize&op=handle', $('#handle').serialize(), function (ret) {
            if (ret.datas) {
                layer.alert('更新成功', function () {
                    location.reload();
                });
            } else {
                layer.alert('更新失败');
            }
        }, 'json');
    });
</script>
